package com.aimei520.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.aimei520.po.admin.Log;
import com.aimei520.po.admin.Role;
import com.aimei520.service.api.LogService;
import com.aimei520.utils.NavListUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 日志记录
 * Title: LogController.java
 * Description:  
 * Copyright: Copyright (c) 2018
 * Company: www.storyboy.xyz 
 * @author JiaXun  
 * @date 2018年9月7日  
 * @version 1.0.0
 */
@Controller
@RequestMapping("/admin")
public class LogController {

	@Resource
	private LogService logService;
	
	
	private int getPageNum(String pageNum) {
		try {
			if(Integer.parseInt(pageNum) > 0 ) {
				return Integer.parseInt(pageNum);
			}
		}catch(Exception e) {
			
		}
		return 1;
	}
	
	@RequestMapping("/loglist")
	public String logList(Model model,String pageNum, HttpServletRequest request) {
		
		PageHelper.startPage(getPageNum(pageNum), 15, true);
		List<Log> log = logService.logList();
		PageInfo<Log> logs = new PageInfo<Log>(log);
		
		model.addAttribute("logs",logs);
		model.addAttribute(
				"page",
				NavListUtils.getNavList(
						request.getContextPath()+request.getServletPath(),getPageNum(pageNum), logs.getNavigatepageNums(), logs.isIsFirstPage(), logs.isIsLastPage()
					)
				);
		
		return "log/logList";
	}
}
